using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The GuardianAddressTableManager class is responsible for managing BO.GuardianAddressTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class GuardianAddressTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all GuardianAddressTable objects in the database.
        /// </summary>
        /// <returns>A list with all GuardianAddressTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static GuardianAddressTableList GetList()
        {
            return GuardianAddressTableDB.GetList();
        }

        /// <summary>
        /// Gets a single GuardianAddressTable from the database without its data.
        /// </summary>
        /// <param name="guardianAddressKey">The GuardianAddressKey of the GuardianAddressTable in the database.</param>
        /// <returns>A GuardianAddressTable object when the GuardianAddressKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static GuardianAddressTable GetItem(int guardianAddressKey)
        {
            return GetItem(guardianAddressKey, false);
        }

        /// <summary>
        /// Gets a single GuardianAddressTable from the database.
        /// </summary>
        /// <param name="guardianAddressKey">The GuardianAddressKey of the GuardianAddressTable in the database.</param>
        /// <param name="getGuardianAddressTableRecords">Determines whether to load all associated GuardianAddressTable records as well.</param>
        /// <returns>
        /// A GuardianAddressTable object when the GuardianAddressKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static GuardianAddressTable GetItem(int guardianAddressKey, bool getGuardianAddressTableRecords)
        {
            GuardianAddressTable myGuardianAddressTable = GuardianAddressTableDB.GetItem(guardianAddressKey);
            return myGuardianAddressTable;
        }


        /// <summary>
        /// Gets a single GuardianAddressTable from the database.
        /// </summary>
        /// <param name="UserAccountKey">The UserAccountKey of the GuardianAddressTable in the database.</param>
        /// <returns>
        /// A GuardianAddressTable object when the UserAccountKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static GuardianAddressTable GetItemByUserAccountKey(int UserAccountKey, Int16 AddressTypeCode)
        {
            GuardianAddressTable myGuardianAddressTable = GuardianAddressTableDB.GetItemByUserAccountKey(UserAccountKey, AddressTypeCode);
            return myGuardianAddressTable;
        }

        /// <summary>
        /// Saves a GuardianAddressTable in the database.
        /// </summary>
        /// <param name="myGuardianAddressTable">The GuardianAddressTable instance to save.</param>
        /// <returns>The new GuardianAddressKey if the GuardianAddressTable is new in the database or the existing GuardianAddressKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(GuardianAddressTable myGuardianAddressTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int guardianAddressTableGuardianAddressKey = GuardianAddressTableDB.Save(myGuardianAddressTable);

                //  Assign the GuardianAddressTable its new (or existing GuardianAddressKey).
                myGuardianAddressTable.GuardianAddressKey = guardianAddressTableGuardianAddressKey;

                myTransactionScope.Complete();

                return guardianAddressTableGuardianAddressKey;
            }
        }

        /// <summary>
        /// Deletes a GuardianAddressTable from the database.
        /// </summary>
        /// <param name="myGuardianAddressTable">The GuardianAddressTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(GuardianAddressTable myGuardianAddressTable)
        {
            return GuardianAddressTableDB.Delete(myGuardianAddressTable.GuardianAddressKey);
        }

        #endregion

    }

}
